package com.xmmj.baselibrary.utils.decoration

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView.ItemDecoration
import androidx.recyclerview.widget.RecyclerView

/**
 * 网格分割线
 */
class GridSpaceItemDecoration(var mVSpace: Int, var mHSpace: Int, var mColumns: Int) :
    ItemDecoration() {
    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        super.getItemOffsets(outRect, view, parent, state)
        val current = parent.getChildAdapterPosition(view) + 1
        outRect.left = mHSpace / 2
        outRect.right = mHSpace / 2
        if (current > mColumns) {
            outRect.top = mVSpace
        }
    }
}